package com.mazaiting.common.core.ex.exceptions;

import com.mazaiting.common.core.domain.result.ResultCode;

/**
 * 自定义异常父类
 *
 * @author mazaiting
 * @create_time 2022/3/25 11:50
 */
public class BaseException extends Exception {

    /**
     * 状态码
     */
    private final Integer code;

    /**
     * 错误消息
     */
    private final String message;

    public BaseException(Integer code, String message) {
        this(code, message, null);
    }

    public BaseException(Integer code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.message = message;
    }

    public BaseException(Integer code, String message, Throwable cause,
                        boolean enableSuppression,
                        boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
        this.code = code;
        this.message = message;
    }

    public BaseException(ResultCode resultCode) {
        this(resultCode.getCode(), resultCode.getMessage());
    }

    public Integer getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }

}
